<?php
namespace BP\GPM;
require_once("BP/Web/WebUser.php");
require_once("BP/En/Map.php");
class App extends EntityNoName {
	public function getOpenWay () 
	{
		$openWay = 0;
		switch ($openWay) {
			case 0:
				return "_blank";
			case 1:
				return $this->getNo();
			default:
				return "";
		}
	}
	public function getWebPath () 
	{
		return $this->GetValStringByKey("WebPath");
	}
	public function getICON () 
	{
		return $this->getWebPath();
	}
	public function setICON ($value) // [String value]
	{
		$this->SetValByKey("ICON", $value);
	}
	public function getUrl () 
	{
		$url = $this->GetValStrByKey(AppAttr::$Url);
		if ($DataType->IsNullOrEmpty($url))
		{
			return "";
		}
		if ($this->getSSOType()->equals("0"))
		{
			$SID = DBAccess->RunSQLReturnStringIsNull((("SELECT SID FROM Port_Emp WHERE No='" . $WebUser->getNo()) . "'"), NULL);
			if ($url->contains("?"))
			{
				$url += ((("&UserNo=" . $WebUser->getNo()) . "&SID=") . $SID);
			}
			else
			{
				$url += ((("?UserNo=" . $WebUser->getNo()) . "&SID=") . $SID);
			}
		}
		return $url;
	}
	public function setUrl ($value) // [String value]
	{
		$this->SetValByKey(AppAttr::$Url, $value);
	}
	public function getSubUrl () 
	{
		return $this->GetValStrByKey(AppAttr::$SubUrl);
	}
	public function setSubUrl ($value) // [String value]
	{
		$this->SetValByKey(AppAttr::$Url, $value);
	}
	public function getIsEnable () 
	{
		return $this->GetValBooleanByKey(AppAttr::$IsEnable);
	}
	public function setIsEnable ($value) // [boolean value]
	{
		$this->SetValByKey(AppAttr::$IsEnable, $value);
	}
	public function getIdx () 
	{
		return $this->GetValIntByKey(AppAttr::$Idx);
	}
	public function setIdx ($value) // [int value]
	{
		$this->SetValByKey(AppAttr::$Idx, $value);
	}
	public function getUidControl () 
	{
		return $this->GetValStrByKey(AppAttr::$UidControl);
	}
	public function setUidControl ($value) // [String value]
	{
		$this->SetValByKey(AppAttr::$UidControl, $value);
	}
	public function getPwdControl () 
	{
		return $this->GetValStrByKey(AppAttr::$PwdControl);
	}
	public function setPwdControl ($value) // [String value]
	{
		$this->SetValByKey(AppAttr::$PwdControl, $value);
	}
	public function getActionType () 
	{
		return $this->GetValStrByKey(AppAttr::$ActionType);
	}
	public function setActionType ($value) // [String value]
	{
		$this->SetValByKey(AppAttr::$ActionType, $value);
	}
	public function getSSOType () 
	{
		return $this->GetValStrByKey(AppAttr::$SSOType);
	}
	public function setSSOType ($value) // [String value]
	{
		$this->SetValByKey(AppAttr::$SSOType, $value);
	}
	public function getFK_AppSort () 
	{
		return $this->GetValStringByKey(AppAttr::$FK_AppSort);
	}
	public function setFK_AppSort ($value) // [String value]
	{
		$this->SetValByKey(AppAttr::$FK_AppSort, $value);
	}
	public function getRefMenuNo () 
	{
		return $this->GetValStringByKey(AppAttr::$RefMenuNo);
	}
	public function setRefMenuNo ($value) // [String value]
	{
		$this->SetValByKey(AppAttr::$RefMenuNo, $value);
	}
	public function getHisUAC () 
	{
		$uac = new UAC();
		$uac->OpenForAppAdmin();
		return $uac;
	}
	public static function constructor__ () 
	{
		$me = new self();
		return $me;
	}
	public static function constructor__String ($no) // [String no]
	{
		$me = new self();
		$me->setNo($no);
		$me->Retrieve();
		return $me;
	}
	public function getEnMap () 
	{
		if (($this->get_enMap() != NULL))
		{
			return $this->get_enMap();
		}
		$map = new Map("GPM_App");
		$map->setDepositaryOfEntity($Depositary->None);
		$map->setDepositaryOfMap($Depositary->Application);
		$map->setEnDesc("系统");
		$map->setEnType($EnType->Sys);
		$map->AddTBStringPK(AppAttr::$No, NULL, "编号",  TRUE ,  FALSE , 2, 30, 100);
		$map->AddDDLSysEnum(AppAttr::$AppModel, 0, "应用类型",  TRUE ,  TRUE , AppAttr::$AppModel, "@0=BS系统@1=CS系统");
		$map->AddTBString(AppAttr::$Name, NULL, "名称",  TRUE ,  FALSE , 0, 3900, 150,  TRUE );
		$map->AddDDLEntities(AppAttr::$FK_AppSort, NULL, "类别", AppSorts::constructor__(),  TRUE );
		$map->AddBoolean(AppAttr::$IsEnable,  TRUE , "是否启用",  TRUE ,  TRUE );
		$map->AddTBString(AppAttr::$Url, NULL, "默认连接",  TRUE ,  FALSE , 0, 3900, 100,  TRUE );
		$map->AddTBString(AppAttr::$SubUrl, NULL, "第二连接",  TRUE ,  FALSE , 0, 3900, 100,  TRUE );
		$map->AddTBString(AppAttr::$UidControl, NULL, "用户名控�?",  TRUE ,  FALSE , 0, 100, 100);
		$map->AddTBString(AppAttr::$PwdControl, NULL, "密码控件",  TRUE ,  FALSE , 0, 100, 100);
		$map->AddDDLSysEnum(AppAttr::$ActionType, 0, "提交类型",  TRUE ,  TRUE , AppAttr::$ActionType, "@0=GET@1=POST");
		$map->AddDDLSysEnum(AppAttr::$SSOType, 0, "登录方式",  TRUE ,  TRUE , AppAttr::$SSOType, "@0=SID验证@1=连接@2=表单提交@3=不传�?");
		$map->AddDDLSysEnum(AppAttr::$OpenWay, 0, "打开方式",  TRUE ,  TRUE , AppAttr::$OpenWay, "@0=新窗口@1=本窗口@2=覆盖新窗�?");
		$map->AddTBString(AppAttr::$RefMenuNo, NULL, "关联菜单编号",  TRUE ,  FALSE , 0, 3900, 100);
		$map->AddTBString(AppAttr::$AppRemark, NULL, "备注",  TRUE ,  FALSE , 0, 500, 500,  TRUE );
		$map->AddTBInt(AppAttr::$Idx, 0, "显示顺序",  TRUE ,  FALSE );
		$map->AddMyFile("ICON");
		$rm = new RefMethod();
		$rm->Title = "编辑菜单";
		$rm->ClassMethodName = ($this . ".DoMenu");
		$rm->refMethodType = $RefMethodType->LinkeWinOpen;
		$map->AddRefMethod($rm);
		$rm = new RefMethod();
		$rm->Title = "查看可访问该系统的人�?";
		$rm->ClassMethodName = ($this . ".DoWhoCanUseApp");
		$rm = new RefMethod();
		$rm->Title = "刷新设置";
		$rm->ClassMethodName = ($this . ".DoRef");
		$rm = new RefMethod();
		$rm->Title = "第二连接";
		$rm->ClassMethodName = ($this . ".About");
		$this->set_enMap($map);
		return $this->get_enMap();
	}
	protected function beforeDelete () 
	{
		$appMenu = Menu::constructor__String($this->getRefMenuNo());
		if ((($appMenu != NULL) && $appMenu->getFlag()->contains("Flow")))
		{
			throw new \RuntimeException("@删除失败,此项为工作流菜单，不能删除�??");
		}
		$menu = Menu::constructor__();
		$menu->Delete(MenuAttr::$FK_App, $this->getNo());
		$em = EmpMenu::constructor__();
		$em->Delete(MenuAttr::$FK_App, $this->getNo());
		$ea = EmpApp::constructor__();
		$ea->Delete(MenuAttr::$FK_App, $this->getNo());
		return parent->beforeDelete();
	}
	protected function beforeUpdate () 
	{
		if (($DataType->IsNullOrEmpty($this->getRefMenuNo()) ==  FALSE ))
		{
			$appSort = AppSort::constructor__String($this->getFK_AppSort());
			$menu = Menu::constructor__String($this->getRefMenuNo());
			$menu->setName($this->getName());
			$menu->setParentNo($appSort->getRefMenuNo());
			$menu->Update();
		}
		return parent->beforeUpdate();
	}
	protected function beforeInsert () 
	{
		$sort = AppSort::constructor__String($this->getFK_AppSort());
		$menu = Menu::constructor__String($sort->getRefMenuNo());
		$tempVar = $menu->DoCreateSubNode();
		$appMenu = ( ($tempVar instanceof Menu) ? $tempVar : NULL );
		$appMenu->setFK_App($this->getNo());
		$appMenu->setName($this->getName());
		$appMenu->setHisMenuType(MenuType::$App);
		$appMenu->Update();
		$this->setRefMenuNo($appMenu->getNo());
		$tempVar2 = $appMenu->DoCreateSubNode();
		$dir = ( ($tempVar2 instanceof Menu) ? $tempVar2 : NULL );
		$dir->setFK_App($this->getNo());
		$dir->setName("功能目录1");
		$dir->setMenuType(MenuType::$Dir);
		$dir->Update();
		$tempVar3 = $dir->DoCreateSubNode();
		$func = ( ($tempVar3 instanceof Menu) ? $tempVar3 : NULL );
		$func->setName("xxx管理1");
		$func->setFK_App($this->getNo());
		$func->setMenuType(MenuType::$Menu);
		$func->setUrl("http://ccflow.org");
		$func->Update();
		$tempVar4 = $func->DoCreateSubNode();
		$funcDot = ( ($tempVar4 instanceof Menu) ? $tempVar4 : NULL );
		$funcDot->setName("查看");
		$funcDot->setMenuType(MenuType::$Function);
		$funcDot->setFK_App($this->getNo());
		$funcDot->Update();
		$tempVar5 = $func->DoCreateSubNode();
		$funcDot = ( ($tempVar5 instanceof Menu) ? $tempVar5 : NULL );
		$funcDot->setName("增加");
		$funcDot->setMenuType(MenuType::$Function);
		$funcDot->setFK_App($this->getNo());
		$funcDot->Update();
		$tempVar6 = $func->DoCreateSubNode();
		$funcDot = ( ($tempVar6 instanceof Menu) ? $tempVar6 : NULL );
		$funcDot->setName("删除");
		$funcDot->setMenuType(MenuType::$Function);
		$funcDot->setFK_App($this->getNo());
		$funcDot->Update();
		return parent->beforeInsert();
	}
	public static function InitBPMMenu () 
	{
		$sort = AppSort::constructor__();
		$sort->setNo("01");
		if (($sort->RetrieveFromDBSources() == 0))
		{
			$sort->setName("应用系统");
			$sort->setRefMenuNo("2000");
			$sort->Insert();
		}
		$app = App::constructor__();
		$app->setNo("CCFlowBPM");
		$app->setName("BPM系统");
		$app->setFK_AppSort("01");
		$app->Insert();
	}
	public function About () 
	{
		return NULL;
	}
	public function DoRef () 
	{
		return ("../../../GPM/WhoCanUseApp.aspx?FK_App=" . $this->getNo());
	}
	public function DoWhoCanUseApp () 
	{
		return ("../../../GPM/WhoCanUseApp.aspx?FK_App=" . $this->getNo());
	}
	public function DoMenu () 
	{
		return ("../../../GPM/AppMenu.htm?FK_App=" . $this->getNo());
	}
	public function RefData () 
	{
		$mymes = EmpMenus::constructor__();
		$mymes->Delete(EmpMenuAttr::$FK_App, $this->getNo());
		$empApps = EmpApps::constructor__();
		$empApps->Delete(EmpMenuAttr::$FK_App, $this->getNo());
		$menus = Menus::constructor__();
		$menus->Retrieve(EmpMenuAttr::$FK_App, $this->getNo());
		$emps = Emps::constructor__();
		$emps->RetrieveAllFromDBSource();
		foreach ($emps->ToJavaList() as $emp) 		{
			$me = EmpApp::constructor__();
			$me->Copy($this);
			$me->setFK_Emp($emp->getNo());
			$me->setFK_App($this->getNo());
			$me->setMyPK((($this->getNo() . "_") . $me->getFK_Emp()));
			$me->Insert();
		}
	}
}
?>
